package com.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.ISysLogDao;
import com.ssm.domain.SysLog;
import com.ssm.service.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class SysLogServiceImpl implements ISysLogService {

    @Autowired
    private ISysLogDao sysLogDao;

    @Override
    public void save(SysLog sysLog) {
        //判断是否存在日志和定义日志id
        //需要syslog表的Id是整型
        /*SysLog sysLogForCountId = sysLogDao.countId();
        String id = "";
        id = sysLogForCountId == null ? "0" : Integer.valueOf(sysLogForCountId.getId()) + 1 + "";
        sysLog.setId(id);*/

        //使用UUID当做日志id
        String uuid = UUID.randomUUID().toString().replace("-", "");
        sysLog.setId(uuid);

        sysLogDao.save(sysLog);
    }

    @Override
    public List<SysLog> findAllSysLog() {

        return sysLogDao.findAllSysLog();
    }

    @Override
    public List<SysLog> findAll(Integer page, Integer size) {
        //用于分页操作
        PageHelper.startPage(page,size);
        return sysLogDao.findAll(page,size);
    }
}
